package es.uji.viselab.benchmark.source;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import es.uji.viselab.experiment.DataArrivalListener;
import es.uji.viselab.network.DataPackage;
import es.uji.viselab.robot.RobotListener;

public abstract class Source {

	List<DataArrivalListener> eventListeners = new ArrayList<DataArrivalListener>();

	public void addDataArrivalListener(DataArrivalListener dal) {
		eventListeners.add(dal);
	}

	protected void notifyDataArrival(DataPackage dn) {
		Iterator<DataArrivalListener> iterator = eventListeners.iterator();
		while (iterator.hasNext()) {
			DataArrivalListener da = iterator.next();
			da.newDataArrived(dn);
		}
	}
	
	public void start(){}

	public void notifyConnectionStablished() {
		Iterator<DataArrivalListener> iterator = eventListeners.iterator();
		while (iterator.hasNext()) {
			DataArrivalListener da = iterator.next();
			da.newConnectionStablished();		}
	}

	public abstract void send(DataPackage dn);

	public abstract void keepReceiving();

	public void addListener(DataArrivalListener dal) {
		eventListeners.add(dal);
	}

	public void addListener(RobotListener rl) {
		// TODO Auto-generated method stub
		
	}
}
